package com.rongchuan.wt.mq.listener;

import com.rongchuan.wt.constant.MessageContant;
import com.rongchuan.wt.entity.EmployeeMessage;
import com.rongchuan.wt.mapper.EmployeeMessageMapper;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(
        consumerGroup ="EmployeeInsertGroup", //消费者小组
        topic = MessageContant.EMPLOYEE_INSERT_TOPIC//主题
)
public class EmployeeInsertListener implements RocketMQListener<EmployeeMessage> {

    @Autowired
    private EmployeeMessageMapper employeeMessageMapper;

    @Override
    public void onMessage(EmployeeMessage employee) {
        if (employee.getId() != null){
            System.out.println("员工:"+employee.getName()+"已入职!");

            employeeMessageMapper.insert(employee);
        }
    }

}
